

from sketchz import *

window = WindowAfter((1000, 800))

from mat_encode import de
from itertools import product
from sdl2.ext import FontTTF
Rect = sdl2.SDL_Rect

font = FontTTF("tuffy.ttf", "60px", (0, 0, 0, 255))       # 尼玛这里就是255级的

all_text = sdl2.ext.surface._create_surface((8*120, 800), (255, 255, 255, 255)).contents


box = Obj()
box1 = make_block(U3(1, 1, 1))
quad = make_quad('xy', 1, 1)

pos_l = []
piece_l = []


data = []

with open("building8.txt") as f:
    for line in f:
        code = line.strip()
        mat = de(code)
        data.append((code, mat))
    
    
for (j, i), (code, mat) in zip(product(range(8), range(8)), data):
    pos_l.append(U3(i * 5+0.5, j * 5+0.5, 3))
    piece_l.append((i * 1/8, j * 1/8, 1/8, 1/8))
    
    text = font.render_text(code[3:], width=150)
    sdl2.SDL_BlitSurface(text, None, all_text, Rect(i *120, j * 100, 100, 100))
    
    base = U3(i * 5, j * 5, 0)
    for z, y, x in product(range(2), range(2), range(2)):
        if mat[z][y][x] == 1:
            box1.t.pos = base + U3(x, 1-y, z)
            box1.as_unit() >> box
    
    for y, x in product(range(2), range(2)):
        quad.t.pos = base + U3(y, x, -0.5)
        quad.as_unit() >> box

box.color = V3(1, 1, 1)
box.u(window)  
box >> window

ads = Ads100(as_image(window.ctx, all_text))
p1 = [-1, 1, 0, 0, 0, 1,  0, 0]
p2 = [-1, -1, 0, 0, 0, 1, 0, 1]
p3 = [1, -1, 0, 0, 0, 1, 1, 1]
p4 = [1, 1, 0, 0, 0, 1,  1, 0]
arr = np.array([p1, p2, p3, p1, p3, p4], dtype="f4")
ads.vertices = arr[:, :3]
ads.normals = arr[:, 3:6]
ads.texcoords = arr[:, 6:]
ads.u(window)  
ads >> window


ads.update100(pos_l, piece_l)

camera = window.camera
camera.t.pos = U3(0, -5, 1)

walker = Walker3(camera)
walker >> window


window.mainloop()
